package com.fzx.aidlservice.bean;

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

/**
 * 描述：    服务端Bean类
 * 注意：客户端和服务端Bean类，类名一定要一样，参数可以不一样，
 * 但是在序列化读写时,各个类型的顺序一定要一致，
 * 数据传递时，总是先执行本端bean类的writeToParcel();然后在另一端执行UserInfo();
 * 例如：in指标（注意传递参数类型）
 * 1.客户端向服务端传递UserInfo，先执行客户端的writeToParcel(Parcel parcel, int i)方法，按顺序将数据传入UserInfo中；
 * 2.在服务端中，接收客户端传递的UserInfo，执行服务端的UserInfo(Parcel in)，按客户端传递的顺序依次接收数据；
 * 3.客户端获取服务端的UserInfo，先执行服务端的writeToParcel(Parcel parcel, int i)方法，按顺序将数据传入UserInfo中；
 * 4.在客户端中，接收服务端传递的UserInfo，执行客户端的UserInfo(Parcel in)，按服务端传递的顺序依次接收数据。
 * 项目名称：AidlDemo
 * 创建人：  FangZhixin
 * 创建时间：2018/8/3
 */
public class UserInfo implements Parcelable {

    private static String TAG = "fzx";
    private String userName;
    private String password;
    private int userId;
    private Bitmap bitmap;
    private int idd;
    private int idd2;
    private int idd3;

    public UserInfo() {
    }

    protected UserInfo(Parcel in) {
        Log.i(TAG, "Service UserInfo: 1");
        userName = in.readString();
        password = in.readString();
        userId = in.readInt();
        bitmap = in.readParcelable(Bitmap.class.getClassLoader());
        idd = in.readInt();
        idd2 = in.readInt();
        idd3 = in.readInt();
        Log.i(TAG, "Service UserInfo: 2");
    }

    public static final Creator<UserInfo> CREATOR = new Creator<UserInfo>() {
        @Override
        public UserInfo createFromParcel(Parcel in) {
            return new UserInfo(in);
        }

        @Override
        public UserInfo[] newArray(int size) {
            return new UserInfo[size];
        }
    };

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public Bitmap getBitmap() {
        return bitmap;
    }

    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    /**
     * 支持in的定向tag
     * @param parcel
     * @param i
     */
    @Override
    public void writeToParcel(Parcel parcel, int i) {
        Log.i(TAG, "Service writeToParcel: 1");
        parcel.writeString(userName);
        parcel.writeString(password);
        parcel.writeInt(userId);
        parcel.writeParcelable(bitmap, i);
        parcel.writeInt(idd2);
        parcel.writeInt(idd);
        parcel.writeInt(idd3);
        Log.i(TAG, "Service writeToParcel: 2");
    }

    /**
     * 支持out的定向tag
     * @param source
     */
    public void readFromParcel(Parcel source) {
        Log.i(TAG, "Service readFromParcel: 1");
        userName = source.readString();
        password = source.readString();
        userId = source.readInt();
        bitmap = source.readParcelable(Bitmap.class.getClassLoader());
        idd2 = source.readInt();
        idd = source.readInt();
        idd3 = source.readInt();
        Log.i(TAG, "Service readFromParcel: 2");
    }

    public int getIdd() {
        return idd;
    }

    public void setIdd(int idd) {
        this.idd = idd;
    }

    public int getIdd2() {
        return idd2;
    }

    public void setIdd2(int idd2) {
        this.idd2 = idd2;
    }

    public int getIdd3() {
        return idd3;
    }

    public void setIdd3(int idd3) {
        this.idd3 = idd3;
    }

    @Override
    public String toString() {
        return "UserInfo{" +
                "userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                ", userId=" + userId +
                ", bitmap=" + bitmap +
                ", idd=" + idd +
                ", idd2=" + idd2 +
                ", idd3=" + idd3 +
                '}';
    }
}
